<template>
  <div class="goods-box3">
    <div class="search">
      <el-input
        v-model="searchValue"
        maxlength="100"
        clearable
        style="width: 290px"
      />
      <img
        src="../assets/img/search.png"
        class="search-icon"
        @click="handleSearch"
      />
      <i style="color: #696969;margin-left: 10px; font-size: 12px; font-style: normal"
        >热门搜索：
        <a class="tag-item" @click="handleTopicDetail('苹果果树种植方法')"
          >苹果果树种植方法
        </a>
        <a class="tag-item" @click="handleTopicDetail('新疆哈密瓜甜度控制')"
          >新疆哈密瓜甜度控制</a
        >
        <a class="tag-item" @click="handleTopicDetail('玉米苗灌溉')"
          >玉米苗灌溉</a
        >
      </i>
    </div>
    <div class="goods" v-for="(item, index) in cgoods" :key="index">
      <div class="info">
        <p class="content">
          <i class="question-text" style="" v-if="item.status == 0">[问]</i>
          <i class="question-text" v-else>[答]</i>
          <span class="question-content" @click="handleDetail(item)">{{
            item.title
          }}</span>
        </p>
        <div class="person-contents">
          <span>提问者：{{ item.questioner }}</span
          >&nbsp;&nbsp;&nbsp;
          <span>专家：{{ item.expertName }}</span>
        </div>
      </div>
    </div>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      @current-change="pageClick"
      :current-page="currentPage"
      :page-count="pageSize"
    />
  </div>
</template>

<script setup>
import { ref, defineProps, defineEmits } from "vue";
import { useRouter } from "vue-router";

const props = defineProps({
  cgoods: Array,
  total: Number,
  pageSize: Number,
  url: String,
});
const emit = defineEmits(["pageClick", "handleSearch"]);

const searchValue = ref("");
const router = useRouter();
const currentPage = ref(1);

const handleSearch = () => {
  emit("handleSearch", searchValue.value);
};

const handleDetail = (item) => {
  router.push(`/home/guideDetail?id=${item.id}`);
};

const handleTopicDetail = (val) => {
  searchValue.value = val;
  handleSearch();
};

const pageClick = (val) => {
  emit("pageClick", val);
};
</script>

<style lang="less" scoped>
.search {
  width: 730px;
  height: 80px;
  background-color: white;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  .tag-item {
    margin-right: 8px;
    cursor: pointer;
  }
  .search-icon,
  .el-input {
    cursor: pointer;
    height: 40px;
  }
}

.goods-box3 {
  width: 730px;
  .goods {
    width: 730px;
    min-height: 80px;
    padding: 10px 20px;
    background-color: white;
    border-radius: 0px;
    border-bottom: 1px solid #f2f2f2;

    .info {
      width: 685px;

      .title {
        /*超出的部分隐藏*/
        overflow: hidden;
        /*文字用省略号替代超出的部分*/
        text-overflow: ellipsis;
        /*弹性伸缩盒子模型显示*/
        display: -webkit-box;
        /*限制在一个块元素显示文本的行数*/
        -webkit-line-clamp: 1;
        /*设置或检索伸缩盒对象的子元素排列方式*/
        -webkit-box-orient: vertical;
      }

      .content {
        width: 680px;
        line-height: 20px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        /*超出的部分隐藏*/
        overflow: hidden;
        /*文字用省略号替代超出的部分*/
        text-overflow: ellipsis;
        /*弹性伸缩盒子模型显示*/
        display: -webkit-box;
        /*限制在一个块元素显示文本的行数*/
        -webkit-line-clamp: 7;
        /*设置或检索伸缩盒对象的子元素排列方式*/
        -webkit-box-orient: vertical;
        .question-text {
          color: #666;
          font-style: normal;
        }
      }
      .person-contents {
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
        font-size: 12px;
        color: #666;
      }
      .price {
        font-size: 15px;
        font-weight: bold;
        display: block;
        color: red;
      }
    }
  }
}
.marginR5 {
  margin-right: 5px;
}
.question-content {
  cursor: pointer;
  &:hover {
    text-decoration: underline;
    color: #035d1c;
  }
}
.search /deep/ .el-input--suffix .el-input__inner {
  height: 35px;
  line-height: 35px;
}
</style>